/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.woundedwolf.android.tumbleweed;

import android.graphics.Color;
import com.woundedwolf.android.tumbleweed.elements.Vector2D;

/**
 *
 * @author FlameDuck
 */
public class Particle extends Pixel
{
	private int startLife;
	private int life;
	private Vector2D speed;

	public Particle(float xpos, float ypos, int life)
	{
		super(new Vector2D(xpos, ypos), Color.WHITE);
		this.speed = new Vector2D(0,0);
		this.life = life;
		this.startLife = life;
	}

	public Particle(Vector2D position, int life)
	{
		this(position.getXpos(), position.getYpos(), life);
	}

	public void update()
	{
		life--;
		if (life < 0)
			life = 0;
		position.add(speed);
		int temp = getLife255();
		color = Color.rgb(temp, temp, temp);
	}

	public boolean isDead()
	{
		return life < 1;
	}

	public void moveParticle(Vector2D direction, boolean inertial)
	{
		if (inertial)
			speed.add(direction);
		else
			speed=direction;
	}

	private int getLife255()
	{
		return new Double( (double) life / startLife * 255d).intValue();

	}
}
